package com.zhengxing.jienci.web.component;

import com.zhengxing.jienci.web.exception.ParamcheckException;
import com.zhengxing.jienci.web.pojo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 浪遏飞舟
 * @create 2020-06-23 11:08
 * 全局异常处理器
 */
//@RestControllerAdvice
public class ExceptionControllerAdvice {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionControllerAdvice.class);

    @ExceptionHandler(ArithmeticException.class)
    public ResultVo<String> arithmeticException(ArithmeticException e){
        LOGGER.error("系统发生算数异常",e.getMessage());
        return ResultVo.error("系统发生算数异常:",e.getMessage());
    }

    //@ExceptionHandler(NullPointerException.class)
    public ResultVo<String> nulllPointerException(NullPointerException e){
        LOGGER.error("系统发生空指针异常",e.getMessage());
        return ResultVo.error("系统发生空指针异常:",e.getMessage());
    }

    @ExceptionHandler(ParamcheckException.class)
    public ResultVo<String> parameCheckException(ParamcheckException e){
        LOGGER.error("请求接口参数异常",e.getMessage());
        return ResultVo.warn(e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public ResultVo<String> runtimeExceptionHandler(RuntimeException e){
        e.printStackTrace();
        LOGGER.error("系统发生运行时异常",e.getMessage());
        return ResultVo.error("系统发生运行时异常:",e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultVo<String> exceptionHandler(Exception e){
        LOGGER.error("系统发生异常",e.getMessage());
        return ResultVo.error("系统发生异常:",e.getMessage());
    }



}
